import java.util.Comparator;
import java.util.Objects;
import java.util.concurrent.Callable;

class Card implements Comparable<Card>{
    public int rank;//数值
    public String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }

    @Override
    public int hashCode() {
        return Objects.hash(rank, suit);
    }

    @Override
    public int compareTo(Card o) {
        return this.rank - o.rank;
    }
}

//实现一个比较器
class RankComparator implements Comparator<Card> {
    @Override
    public int compare(Card o1, Card o2) {
        return o1.rank - o2.rank;
    }
}

public class Test {
    public static void main(String[] args) {
        Card card1 = new Card(1,"方片");
        Card card2 = new Card(1,"方片");
        System.out.println(card1.equals(card2));
        System.out.println(card1.compareTo(card2));
        RankComparator rankComparator = new RankComparator();
        rankComparator.compare(card1, card2);
    }
}
